#reduce(lambda x,y:x+str(y),v,'')

def water(L,M,N,O):
	from collections import defaultdict as mem
	from itertools import permutations as pm
	LMN=[L,M,N]
	mem=mem(int)
	pm=list(pm(range(3),2))
	
	def pouring(lmn,op):
		lmn=[i for i in lmn]
		src,dest=op
		amount=min(lmn[src],LMN[dest]-lmn[dest])
		lmn[src]-=amount
		lmn[dest]+=amount
		return lmn
	def pour(candi,depth):
		lst=[]
		for c in candi:
			if O in c:
				print depth
				return c
			for o in pm:
				t=pouring(c,o)
				if mem[tuple(t)]:continue
				mem[tuple(t)]=c
				lst.append(t)
		if lst:
			return pour(lst,depth+1)
	trace=pour([[L,0,0]],0)
	if trace:
		while(trace!=[L,0,0]):
			print trace
			trace=mem[tuple(trace)]
	print trace
# water(100,24,30)
# water(80,45,35)
water(input(),input(),input(),input())
	
		
		
		